//
//  CertificateViewController.m
//  Village
//
//  Created by longrise on 2017/9/15.
//  Copyright © 2017年 程虎. All rights reserved.
//

#import "CertificateViewController.h"

@interface CertificateViewController ()
@property (nonatomic ,strong)NSString *style; //1 补全信息 2 跳转方式 模态
@property (nonatomic ,strong) UITextField *text;
@property (nonatomic ,strong) UITextField *text1;

@property (nonatomic ,strong) UILabel *text3;
@end

@implementation CertificateViewController


- (void)setParams:(id)obj block:(LongriseRouterBlock)block
{
    _style = (NSString *)obj;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kBackgroundColor;
    // Do any additional setup after loading the view.
    self.title = @"证件信息";
    
   
    
    if ([_style isEqualToString:@"1"]){
        UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(onClickedOKbtn)];
        [rightBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                              [UIFont systemFontOfSize:15], NSFontAttributeName,
                                              [UIColor whiteColor], NSForegroundColorAttributeName,
                                              nil]
                                    forState:UIControlStateNormal];
        
        [rightBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                              [UIFont systemFontOfSize:15], NSFontAttributeName,
                                              [UIColor whiteColor], NSForegroundColorAttributeName,
                                              nil]
                                    forState:UIControlStateHighlighted];
        self.navigationItem.rightBarButtonItem = rightBarItem;
        [self setnowview];
    }else{
        [self setview];
    }
}

- (void)setnowview{
    UILabel *lab = [[UILabel alloc]  initWithFrame:CGRectMake(15, 12, 150, 23)];
    lab.text = @"请补全你的证件信息";
    lab.textColor = [Util colorWithHexString:@"999999"];
    lab.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:lab];
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 45, kDeviceWidth, 150)];
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
    
    UILabel *lab1 = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, 80, 30)];
    lab1.text = @"真实姓名";
    lab1.font = [UIFont systemFontOfSize:17];
    [view addSubview:lab1];
    
    UILabel *lab2 = [[UILabel alloc] initWithFrame:CGRectMake(15, 60, 80, 30)];
    lab2.text = @"证件类型";
    lab2.font = [UIFont systemFontOfSize:17];
    [view addSubview:lab2];
    
    UILabel *lab3 = [[UILabel alloc] initWithFrame:CGRectMake(15, 110, 80, 30)];
    lab3.text = @"证件号码";
    lab3.font = [UIFont systemFontOfSize:17];
    [view addSubview:lab3];
    
    
    UIView *viewa = [[UIView alloc] initWithFrame:CGRectMake(10, 50, kDeviceWidth -20, 2)];
    viewa.backgroundColor = kBackgroundColor;
    [view addSubview:viewa];
    
    UIView *viewb = [[UIView alloc] initWithFrame:CGRectMake(10, 100, kDeviceWidth -20, 2)];
    viewb.backgroundColor = kBackgroundColor;
    [view addSubview:viewb];

    
    
    _text = [[UITextField alloc] initWithFrame:CGRectMake(100, 10, 200, 30)];
    _text.placeholder = @"请输入您的真实姓名";
    _text.font = [UIFont systemFontOfSize:17];
    [view addSubview:_text];
    
    
    _text3 = [[UILabel alloc] initWithFrame:CGRectMake(100, 60, 150, 30)];
    _text3.text = @"身份证";
     _text3.textColor = [Util colorWithHexString:@"999999"];
    _text3.font = [UIFont systemFontOfSize:17];
    [view addSubview:_text3];

    _text1 = [[UITextField alloc] initWithFrame:CGRectMake(100, 110, 250, 30)];
    _text1.placeholder = @"请输入您证件号码";
    _text1.font = [UIFont systemFontOfSize:17];
    [view addSubview:_text1];

    UILabel *lab4 = [[UILabel alloc]  initWithFrame:CGRectMake(15, 212, 300, 50)];
    lab4.text = @"证件信息设置后不能修改";
    lab4.numberOfLines = 0;//表示label可以多行显示
    lab4.textColor = [Util colorWithHexString:@"999999"];
    lab4.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:lab4];

}
- (void)setview{
    
    UILabel *lab = [[UILabel alloc]  initWithFrame:CGRectMake(15, 12, 150, 23)];
    lab.text = @"你的证件信息已设置";
    lab.textColor = [Util colorWithHexString:@"999999"];
    lab.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:lab];
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 45, kDeviceWidth, 150)];
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
    
    UILabel *lab1 = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, 80, 30)];
    lab1.text = @"真实姓名";
    lab1.textColor = [Util colorWithHexString:@"999999"];

    lab1.font = [UIFont systemFontOfSize:17];
    [view addSubview:lab1];
    
    UILabel *lab2 = [[UILabel alloc] initWithFrame:CGRectMake(15, 60, 80, 30)];
    lab2.text = @"证件类型";
    lab2.textColor = [Util colorWithHexString:@"999999"];

    lab2.font = [UIFont systemFontOfSize:17];
    [view addSubview:lab2];
    
    UILabel *lab3 = [[UILabel alloc] initWithFrame:CGRectMake(15, 110, 80, 30)];
    lab3.text = @"证件号码";
    lab3.textColor = [Util colorWithHexString:@"999999"];

    lab3.font = [UIFont systemFontOfSize:17];
    [view addSubview:lab3];
    
//    UILabel *lab5 = [[UILabel alloc] initWithFrame:CGRectMake(15, 160, 80, 30)];
//    lab5.text = @"审核状态";
//    lab5.textColor = [Util colorWithHexString:@"999999"];
    
    
    UIView *viewa = [[UIView alloc] initWithFrame:CGRectMake(10, 50, kDeviceWidth -20, 2)];
    viewa.backgroundColor = kBackgroundColor;
    [view addSubview:viewa];
    
    UIView *viewb = [[UIView alloc] initWithFrame:CGRectMake(10, 100, kDeviceWidth -20, 2)];
    viewb.backgroundColor = kBackgroundColor;
    [view addSubview:viewb];
    
    UIView *viewc = [[UIView alloc] initWithFrame:CGRectMake(10, 150, kDeviceWidth -20, 2)];
    viewc.backgroundColor = kBackgroundColor;
    [view addSubview:viewc];
    

    
//    lab5.font = [UIFont systemFontOfSize:17];
//    [view addSubview:lab5];

    UILabel *lab6 = [[UILabel alloc] initWithFrame:CGRectMake(100, 10, 180, 30)];
//    if ([Globle getInstance].account.username == nil){
//        lab6.text = [Globle getInstance].account.username;
//    }else{
//        NSString *str = [Globle getInstance].account.username;
//        str = [str stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:@"*"];
//        lab6.text = str;
//    }
     lab6.text = [Globle getInstance].account.username;
    [view addSubview:lab6];
    UILabel *lab7 = [[UILabel alloc] initWithFrame:CGRectMake(100, 60, 180, 30)];
    lab7.text = @"身份证";
  
     [view addSubview:lab7];
    UILabel *lab8 = [[UILabel alloc] initWithFrame:CGRectMake(100, 110, 180, 30)];
    lab8.text = [Globle getInstance].account.cardno;
 
   [view addSubview:lab8];
    
//    UILabel *lab9 = [[UILabel alloc] initWithFrame:CGRectMake(100, 160, 180, 30)];
//    lab9.text = @"已通过";
//
//    [view addSubview:lab9];

    
    UILabel *lab4 = [[UILabel alloc]  initWithFrame:CGRectMake(15, 212, 300, 50)];
    lab4.text = @"证件信息设置后不能修改";
    lab4.numberOfLines = 0;//表示label可以多行显示
    lab4.textColor = [Util colorWithHexString:@"999999"];
    lab4.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:lab4];
    
    
}

- (void)onClickedOKbtn{
    
    if (_text.text.length < 2){
         [MBProgressHUD showError:@"请输入姓名" toView:self.navigationController.view];
    }else{
        if ([Tools valiPenson:_text1.text]){
            
            NSMutableDictionary *bean = [NSMutableDictionary dictionary];
            NSMutableDictionary *dict = [NSMutableDictionary dictionary];
            [dict setObject:[Globle getInstance].account.userid forKey:@"id"];
            [dict setObject:_text.text forKey:@"username"];
            [dict setObject:_text1.text forKey:@"cardno"];
            [bean setValue:dict forKey:@"entitybean"];
            [NetRequestClass Post:UpdateUserInfoURL Parameters:bean success:^(id result) {
                [MBProgressHUD hideHUDForView:self.navigationController.view];
                [MBProgressHUD showSuccess:result[@"message"] toView:self.navigationController.view Completion:nil];
                [[Globle getInstance] saveAccountInfo:result[@"data"]];
                [self.navigationController popViewControllerAnimated:YES];
                LSLog(@"msg -----  %@",result);
            } failure:^(id valueCode, id error) {
                [MBProgressHUD hideHUDForView:self.navigationController.view];
                [MBProgressHUD showError:error toView:self.navigationController.view];
            }];
            
            if ([_style isEqualToString:@"1"]) {
                [self.navigationController popViewControllerAnimated:YES];
            }
            else {
                [self dismissViewControllerAnimated:YES completion:nil];
            }
            
        }else{
            
            [MBProgressHUD showError:@"请输入正确的身份证号码" toView:self.navigationController.view];
        }
        
    }
    
   

}


#pragma mark - 取消
- (void)dismissbtnCilck
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
